package com.twentytwok.hospitalsystem22K.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.twentytwok.hospitalsystem22K.common.PieBo;
import com.twentytwok.hospitalsystem22K.mapper.DrugMapper;
import com.twentytwok.hospitalsystem22K.pojo.Drug;
import com.twentytwok.hospitalsystem22K.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @program: hospital
 * @description: 药物信息管理服务层接口实现类
 * @author: Mr.Wu
 * @create: 2021-11-09 10:58
 **/
@Service("drugService")
public class DrugServiceImpl implements DrugService {

    @Resource
    private DrugMapper drugMapper;


    @Override
    public PageInfo<Drug> findAllDrug(Map<String, Object> map) {
        int limit = map.get("limit") == null ? 15 :Integer.parseInt(map.get("limit")+"");
        int page = map.get("page") == null ? 1 :Integer.parseInt(map.get("page")+"");
        PageHelper.startPage(page, limit);
        List<Drug> drugs = drugMapper.selectByExampleMine(map);

        PageInfo<Drug> drugPageInfo = new PageInfo<>(drugs);
        return drugPageInfo;
    }

    @Override
    public int insertDrug(Map<String, Object> map) {

        return drugMapper.insertDrug(map);
    }

    @Override
    public int updateDrug(Map<String, Object> map) {

        return drugMapper.updateDrug(map);
    }

    @Override
    public int deleteDrug(Integer id) {

        return drugMapper.deleteDrug(id);
    }

    @Override
    public List<PieBo> pie() {
        return drugMapper.pie();
    }


}
